package com.zhangck.bos2_0.action.take_delivery;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.zhangck.bos2_0.Service.take_delivery.WayBillquickServices;
import com.zhangck.bos2_0.common.BaseAction;

import cn.itcast.bos.domain.take_delivery.WayBill;

/** 
* @author 上午茶
* @version 创建时间：2018年6月12日 下午10:41:28 
* 类说明 
*/
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class WayBillquickAction extends BaseAction<WayBill> {
	
	@Autowired
	private WayBillquickServices wayBillServices;
	
	@Action(value="wayBill_save",results={@Result(name="success" , type="json")})
	public String wayBill_save(){
		Map<Object,Object> map = new HashMap<>();
		try {
			wayBillServices.save(model);
			map.put("falg", true);
			map.put("msg", "保存成功");
		} catch (Exception e) {
			map.put("flag", false);
			map.put("msg", "保存失败");
			return "success";
		}
		ActionContext.getContext().getValueStack().push(map);
		return "success";
	}
	

	@Action(value="wayBill_pageFind",results={@Result(name="success" , type="json")})
	public String wayBill_pageFind(){
		System.out.println(model.getWayBillNum()+"aaaaa11231");
		Pageable request = new PageRequest(page-1, rows,Direction.DESC,"id");
		System.out.println(page+"zzzzzzz1111111");
		 Page<WayBill> page = wayBillServices.pageData(model,request);
		 
		 pushPageDataValueStack(page);
		return "success";
	}
	
	@Action(value="wayBillNum_find",results={@Result(name="success" , type="json")})
	public String wayBillNum_find(){
		 WayBill wayBill =  wayBillServices.findWayBillNum(model.getWayBillNum());
		 Map<String, Object> map = new HashMap<>();
		 try {
			 map.put("success", true);
			 map.put("orderData", wayBill);
		} catch (Exception e) {
			map.put("success", false);
			 map.put("orderData", wayBill);
		}
		 ActionContext.getContext().getValueStack().push(map);
		return "success";
	}
	
	@Action(value="wayBillsave_action",results={@Result(name="success", type="json")})
	public String wayBillsave(){
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			wayBillServices.save(model);
			// 保存成功
			result.put("success", true);
			result.put("msg", "保存运单成功！");
		} catch (Exception e) {
			e.printStackTrace();
			// 保存失败
			result.put("success", false);
			result.put("msg", "保存运单失败！");
		}
		ActionContext.getContext().getValueStack().push(result);
		return "success";
	}
}
